package com.topscore.uke.mvp.presenters;

import com.topscore.uke.entities.BuyOneGetOneItem;
import com.topscore.uke.mvp.contractors.BuyOneGetOneContractor;
import com.topscore.uke.mvp.model.BuyOneGetOneModel;
import com.topscore.uke.network.BaseResponse;
import com.topscore.uke.utils.UserInfoManager;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

public class GetBuyOneGetOnePresenter implements BuyOneGetOneContractor.Presenter, BuyOneGetOneContractor {

    private View mView;
    private Model mModel;

    public GetBuyOneGetOnePresenter(View view) {
        this.mView = view;
        mModel = new BuyOneGetOneModel(new Model.CallBack() {
            @Override
            public void onSuccess(BaseResponse<List<BuyOneGetOneItem>> response) {
                mView.onGetDataSuccess(response.getData());
            }

            @Override
            public void onError(int errorCode, String errorMessage) {
                mView.onFail(errorCode,errorMessage);
            }

            @Override
            public void onComplete() {
                mView.onLoadFinished();
            }
        });
    }

    @Override
    public void getBuyOnGetOneData(String status) {
        mView.onLoading("");
        Map<String,Object> request= new HashMap<>();
        request.put("shareUserNo", UserInfoManager.getUserInfo().getLoginName());
        request.put("status",status);
        mModel.getData(request);
    }
}
